//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
//
// (C) Copyright 2006 Marvell International Ltd.
// All Rights Reserved
//
/****************************************************
    (C) Copyright 2006 Marvell International Ltd.
    All Rights Reserved
*****************************************************/

#ifndef __QCI_H__
#define __QCI_H__

#include "xllp_defs.h"

#include "xllp_ci.h"

// qci interface to sensor
typedef struct 
{
    XLLP_CI_MODE mode;
    XLLP_CI_DATA_WIDTH data_width;
    unsigned int clock;
    int pclk_polarity;
    int hsync_polarity;
    int vsync_polarity;
} qci_interface_t;

typedef struct
{
    unsigned int width;
    unsigned int height;
    XLLP_CI_MP_TIMING timing;
} qci_master_timing_t;

typedef struct
{
    unsigned int black_level;
    XLLP_CI_CMU_COE_MATRIX coe;
    unsigned char *lut;
    unsigned int scale;
} qci_image_proc_cfg_t;

// a physically continuous dma buffer
typedef struct
{
    char *buf;
    unsigned int phy_addr;
    unsigned int size;
} dma_buf_t;

// a color plan for one DMA channel
typedef struct
{
    dma_buf_t buf;
    dma_buf_t desc_buf;
} plane_t;

typedef struct
{
    int format;
    unsigned int width;
    unsigned int height;
    BOOL is_still;
} format_t;

struct frame_s;

typedef struct
{
    format_t format;
    struct frame_s *head;
    struct frame_s *tail;
} frame_list_t;

// a frame consist of 1 or 3 color planes
typedef struct frame_s
{
    plane_t plane[3];
    struct frame_s *next;
    frame_list_t *list;
} frame_t;

#define MAX_CALLBACK_NUM 3

typedef void (*capture_callback_t)(ULONG user, ULONG mode);

typedef struct callback_data_s
{
    capture_callback_t callback;
    ULONG user;
    ULONG mode;
    frame_t** frame;
} callback_data_t;

#define _QCI_ACCESS_CTL_CODE(_Function)  \
    CTL_CODE(FILE_DEVICE_UNKNOWN, _Function, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define IOCTL_QCI_SET_INTERFACE		_QCI_ACCESS_CTL_CODE(1)
#define IOCTL_QCI_ENABLE		_QCI_ACCESS_CTL_CODE(2)
#define IOCTL_QCI_START_CAPTURE 	_QCI_ACCESS_CTL_CODE(3)
#define IOCTL_QCI_STOP_CAPTURE 		_QCI_ACCESS_CTL_CODE(4)
#define IOCTL_QCI_SET_MASTER_TIMING	_QCI_ACCESS_CTL_CODE(5)
#define IOCTL_QCI_SET_IMAGE_FORMAT	_QCI_ACCESS_CTL_CODE(6)
#define IOCTL_QCI_SET_CAPTURE_CALLBACK	_QCI_ACCESS_CTL_CODE(7)
#define IOCTL_QCI_NOTIFY_FORMAT         _QCI_ACCESS_CTL_CODE(8)
#define IOCTL_QCI_SET_FRAME_FORMAT      _QCI_ACCESS_CTL_CODE(9)
#define IOCTL_QCI_SET_IMAGE_PROC_CFG           _QCI_ACCESS_CTL_CODE(10)
#define IOCTL_QCI_CLOCK_ENABLE           _QCI_ACCESS_CTL_CODE(11)

#endif /* __QCI_H__ */